From: Matthieu Gallien Date: Wed, 7 May 2025 21:54:52 +0000 (+0200) Subject: fix(readonly): use native separator in paths before calling windows API X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1^2~13^2~1^2~24^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=78d7523ff825460057a1c560482c7c088c659151;p=nextcloud-desktop.git fix(readonly): use native separator in paths before calling windows API we need platform native separators for file paths that will be used in native Windows platform specific APIs Signed-off-by: Matthieu Gallien --- diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index 38747f870..e2b4837f4 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -116,15 +116,16 @@ void FileSystem::setFileReadOnly(const QString &filename, bool readonly) return; } - const auto fileAttributes = GetFileAttributesW(filename.toStdWString().c_str()); + const auto windowsFilename = QDir::toNativeSeparators(filename); + const auto fileAttributes = GetFileAttributesW(windowsFilename.toStdWString().c_str()); if (fileAttributes == INVALID_FILE_ATTRIBUTES) { const auto lastError = GetLastError(); auto errorMessage = static_cast(nullptr); if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errorMessage, 0, nullptr) == 0) { - qCWarning(lcFileSystem()) << "GetFileAttributesW" << filename << (readonly ? "readonly" : "read write") << errorMessage; + qCWarning(lcFileSystem()) << "GetFileAttributesW" << windowsFilename << (readonly ? "readonly" : "read write") << errorMessage; } else { - qCWarning(lcFileSystem()) << "GetFileAttributesW" << filename << (readonly ? "readonly" : "read write") << "unknown error" << lastError; + qCWarning(lcFileSystem()) << "GetFileAttributesW" << windowsFilename << (readonly ? "readonly" : "read write") << "unknown error" << lastError; } return; } @@ -136,14 +137,14 @@ void FileSystem::setFileReadOnly(const QString &filename, bool readonly) newFileAttributes = newFileAttributes & (~FILE_ATTRIBUTE_READONLY); } - if (SetFileAttributesW(filename.toStdWString().c_str(), newFileAttributes) == 0) { + if (SetFileAttributesW(windowsFilename.toStdWString().c_str(), newFileAttributes) == 0) { const auto lastError = GetLastError(); auto errorMessage = static_cast(nullptr); if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errorMessage, 0, nullptr) == 0) { - qCWarning(lcFileSystem()) << "SetFileAttributesW" << filename << (readonly ? "readonly" : "read write") << errorMessage; + qCWarning(lcFileSystem()) << "SetFileAttributesW" << windowsFilename << (readonly ? "readonly" : "read write") << errorMessage; } else { - qCWarning(lcFileSystem()) << "SetFileAttributesW" << filename << (readonly ? "readonly" : "read write") << "unknown error" << lastError; + qCWarning(lcFileSystem()) << "SetFileAttributesW" << windowsFilename << (readonly ? "readonly" : "read write") << "unknown error" << lastError; } }